<template>
    <view>
        <view class="load" v-if="!load">
            <u-loading-icon mode="circle" inactive-color="#fff" text="正在加载..." vertical></u-loading-icon>
        </view>
        <view v-else class="activityBox">
            <actCell :item="ballInfo" :showMap="true" :goNext="2"></actCell>
            <view class="statusbox actBGBox">
                <view class="CheckNumber">
                    <view class="chetext">{{ '票号 ' + (ballInfo.Item[0].ActionCode ? ballInfo.Item[0].ActionCode : '') }}</view>
                    <view class="statustext">{{ getBallyuyue(ballInfo.Item[0]) }}</view>
                </view>
                <view class="codebox">
                    <image class="codeimg" :src="ballInfo.Item[0].QRImg" @click="lookimg(ballInfo.Item[0].QRImg)">
                    </image>
                    <view class="codetext">请向发起人出示票码</view>
                    <view class="shadwbox" v-if="ballInfo.Item[0].Status != 1">
                        {{getBallyuyue(ballInfo.Item[0])}}
                    </view>
                    <image v-if="ballInfo.Status == 3" class="Expire"
                        src="https://wavestation.oss-cn-shenzhen.aliyuncs.com/upload/17229367574241280.png"></image>
                </view>
								<block>
                 <view v-if="ballInfo.Item[0].Status <=1 && ballInfo.Item[0].Status != -2" class="codebtn" @click.stop="cancelSign()">取消报名</view>
								</block>
                <!-- <view v-if="ballInfo.Status !=2" class="codebtn">分享票码</view> -->
                <!-- <view v-else class="codebtn2">分享票码</view> -->
            </view>
            <view class="orinfo actBGBox">
                <!-- <view class="infobox">
                    <view class="infotext">订单编号</view>
                    <view class="context">12345678954</view>
                </view> -->
                <view class="infobox">
                    <view class="infotext">下单时间</view>
                    <view class="context">{{ $util.unixDatetime(ballInfo.Item[0].CreateTime,'yymmddhhmm') }}</view>
                </view>
            </view>
            <!-- <view class="Customer">
                <view class="custext">
                    <text class="text5">仍有疑问？</text>
                    <text class="text6">联系客服</text>
                </view>
                <image class="cusimg" src=""></image>
            </view> -->
        </view>
    </view>
</template>

<script>
import actCell from './components/actCell/actCell.vue';
export default {
    components: {
        actCell
    },
    data() {
        return {
            load: false,
            imageList: [],
            ballInfo: {},
            longitude: '',
            latitude: '',
            ID: '',
        };
    },
    onLoad(e) {
        this.ID = e.id
        this.getDetail()
    },
    //下拉刷新
    onPullDownRefresh() {
        this.getDetail()
        uni.stopPullDownRefresh()
    },
    methods: {
			async cancelSign() {
				let _this = this
				let con = this.ballInfo.Item.find(item=>item.UserID==uni.getStorageSync('user').UserID)
				if(!con){
					_this.$pv.msg('未找到报名信息');
					return
				}
			  uni.showModal({
					title: '温馨提示',
					content: '您确认要取消报名吗',
					showCancel: true,
					success: async function (res) {
						if (res.confirm) {
							_this.$pv.load();
							let r = await _this.$api.post('Appointment/UserCancel', {
								ID: con.ID
							});
							if(r.data){
								_this.$pv.msg('已取消');
								uni.$emit('circleUpdate')
								_this.getDetail()
							}
							
						}
					}
				});
			},
        async payReturn() {
            let _this = this
            uni.showModal({
                title: "温馨提示",
                content: '您确定退票吗？',
                confirmText: "确定",
                success: async function (res) {
                    if (res.confirm) {
                        let res1 = await _this.$api.post('Payment/Return', {
                            EventID: _this.ballInfo.Item[0].ID,
                            EventType: '活动'
                        })
                        if (res1.code == 0) {
                            _this.$pv.msg('退款成功')
                            _this.getDetail()
                        }else{
                            _this.$pv.msg(res1.message)
                        }
                    } else if (res.cancel) {
                    }
                },
            });
        },
        getBallyuyue(obj) {
            if (obj.Status == 0) {
                return '';
            } else if (obj.Status == 1) {
                return "待使用";
            } else if (obj.Status == 2) {
                return "已使用"
            } else if (obj.Status == 3) {
                return "已完成"
            }else if (obj.Status == -2) {
                return "已退款"
            } else if (obj.Status == -1) {
                return ""
            }
        },
        lookimg(url) {
            uni.previewImage({
                current: 0,
                //这个是图片的数据，
                urls: [url]
            })
        },
        async getlog() {
            let loc = await this.getLocationSysc();
            this.longitude = loc.longitude;
            this.latitude = loc.latitude;
        },
        async getDetail() {
            let res = await this.$api.post('Appointment/MySignDetail', {
                ActionCode: this.ID,
            });
            if (res.code == 0) {
                this.ballInfo = res.data;
								if(res.data.Images){
									
                this.imageList = res.data.Images.split(',')
								}
                this.load = true
            }
        },
        getTime2(l) {
            let d = new Date(l);
            let timestamp = d.getTime();
            return this.$u.date(timestamp, 'mm-dd');
        },
    },
}
</script>
<style lang='scss'>
page {
    background-color: #f6f6f6;
}

.activityBox {
    width: 100%;
    padding: 24rpx 32rpx;
}

.actBGBox {
    background: #FFFFFF;
    border-radius: 16rpx;
    padding: 32rpx;
    margin-bottom: 24rpx;
}

.statusbox {
    background-color: #fff;

    .CheckNumber {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding-bottom: 30rpx;
        border-bottom: 1rpx solid #e4e4e4;

        .chetext {
            font-size: 28rpx;
            color: #999999;
        }

        .statustext {
            font-size: 28rpx;
            color: #999999;
            margin-left: auto;
        }
    }

    .codebox {
        margin-top: 72rpx;
        text-align: center;
        position: relative;

        .codeimg {
            width: 248rpx;
            height: 248rpx;
            background-color: #333333;
        }

        .codetext {
            font-size: 24rpx;
            color: #999999;
            margin-top: 32rpx;
        }
        .shadwbox{
            width: 248rpx;
            height: 248rpx;
            background-color: rgba(0, 0, 0, 0.5);
            font-size: 28rpx;
            color: #fff;
            display: flex;
            justify-content: center;
            align-items: center;
            position: absolute;
            top: 0rpx;
            left: 50%;
            transform: translateX(-50%);
        }
        .Expire {
            width: 164rpx;
            height: 160rpx;
            position: absolute;
            top: 50rpx;
            left: 50%;
            transform: translateX(-50%);
        }
    }

    .codebtn {
        padding: 8rpx 14rpx;
				width: 130rpx;
        border: 2rpx solid #CBCBCB;
        // background: #706EEE;
        // color: #fff;
        background: #fff;
        color: #999999;
        border-radius: 48rpx;
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 0 auto;
        margin-top: 32rpx;
        
        font-size: 24rpx;
    }

    .codebtn2 {
        width: 296rpx;
        height: 72rpx;
        background: #d7d7d7;
        border-radius: 48rpx;
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 0 auto;
        margin-top: 32rpx;
        color: #fff;
        font-size: 28rpx;
    }
}

.orinfo {
    .infobox {
        display: flex;
        align-items: center;
        justify-content: space-between;
        // padding-bottom: 30rpx;
        border-bottom: 1rpx solid #e4e4e4;
        margin-bottom: 30rpx;

        .infotext {
            font-size: 28rpx;
            color: #333333;
        }

        .context {
            font-size: 28rpx;
            color: #333333;
        }
    }
}

.orinfo .infobox:last-child {
    border-bottom: 0 !important;
    margin-bottom: 0rpx !important;
}

.Customer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 24rpx;

    .custext {
        .text5 {
            font-size: 24rpx;
            color: #999999;
        }

        .text6 {
            font-size: 24rpx;
            color: #706EEE;
        }
    }

    .cusimg {
        width: 36rpx;
        height: 36rpx;
    }
}
</style>